package com.spera.genutil;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.spring.security.core.feature.cache.redis.RedisCache;
import com.spring.security.core.util.ApplicationUtils;

public class SpUtil {
	public static Map<String, Object> checkToken(String token,RedisCache redisCache) {
		Map<String, Object> s = new HashMap<String, Object>();
		if (!ApplicationUtils.isNotNull(token)) {
			s.put(ApplicationUtils.STATUS, "0");
			s.put(ApplicationUtils.MSG, "请先登录");
			return s;
		} else {
			if (!redisCache.exists(token)) {
				s.put(ApplicationUtils.STATUS, "-9999");
				s.put(ApplicationUtils.MSG, "用户登录已失效，请先重新登录");
				return s;
			} else{
				return null;
			}
		}
	}
	
	public static String getSessionId(){
		RequestAttributes ra = RequestContextHolder.getRequestAttributes();  
	    ServletRequestAttributes sra = (ServletRequestAttributes)ra;  
	    HttpServletRequest request = sra.getRequest();
	    return request.getSession().getId();
	}
}
